<!--
 * @Descripttion: 公众号设置
 * @Author: DXV-RGWU-TUFH-RFCY-IEGMYY
 * @Date: 2020-07-06 12:17:07
 * @LastEditors: DXV-RGWU-TUFH-RFCY-IEGMYY
 * @LastEditTime: 2023-08-28 18:26:39
-->
<template>
  <div class="lb-system-h5">
    <top-nav></top-nav>
    <div class="page-main">
      <el-form
        @submit.native.prevent
        :model="subForm"
        :rules="subFormRules"
        ref="subForm"
        label-width="140px"
      >
        <el-form-item label="AppID" prop="web_app_id">
          <el-input
            v-model="subForm.web_app_id"
            placeholder="请输入公众号AppID"
          ></el-input>
          <lb-tool-tips
            >请输入公众号AppID，输入错误会影响H5的正常使用，谨慎修改</lb-tool-tips
          >
        </el-form-item>
        <el-form-item label="AppSecret" prop="web_app_secret">
          <el-input
            v-model="subForm.web_app_secret"
            placeholder="请输入公众号AppSecret"
          ></el-input>
          <lb-tool-tips
            >请输入公众号AppSecret，输入错误会影响H5的正常使用，谨慎修改</lb-tool-tips
          >
        </el-form-item>
        <el-form-item label="腾讯地图key" prop="map_secret">
          <el-input
            v-model="subForm.map_secret"
            placeholder="请输入腾讯地图key"
          ></el-input>
          <lb-tool-tips
            >请输入腾讯地图key，输入错误会影响H5的正常使用，谨慎修改
            <div class="mt-sm">
              系统主要需要使用腾讯地图的“逆地址解析”、“IP定位”、“地点搜索”等功能，超过限制额度后，对应相关功能将无法使用
            </div>
            <div class="mt-sm">
              请登录腾讯地图开发者平台，确认调用量限制数量，若还未认证企业开发者，建议尽快认证
            </div>
            <div class="mt-lg">
              <a
                class="c-link cursor-pointer"
                href="https://docs.qq.com/doc/DWkNrWGVRWEVtTGV4"
                target="_blank"
                >如何配置腾讯地图Key？</a
              >
            </div>
            <div class="mt-sm">
              <a
                class="c-link cursor-pointer"
                href="https://docs.qq.com/doc/DWmRFUFRMRVRxQ0Rj"
                target="_blank"
                >如何查看腾讯地图应用配额？</a
              >
            </div>
          </lb-tool-tips>
        </el-form-item>
        <el-form-item label="扫码到公众号" prop="wechat_qr_type">
          <el-radio-group v-model="subForm.wechat_qr_type">
            <el-radio :label="1">{{ $t('action.ON') }}</el-radio>
            <el-radio :label="0">{{ $t('action.OFF') }}</el-radio>
          </el-radio-group>
          <lb-tool-tips
            >开启扫码到公众号，需到公众号配置服务器配置，服务器地址域名+massage/CallBack/valid
            <div class="mt-sm">
              当用户扫描分销合伙人的推广海报/渠道码，会直接跳转到公众号界面，若关闭则默认跳转到系统里面的引导用户关注公众号的页面
            </div>
            <div @click="showDialog = true" class="cursor-pointer c-link mt-md">
              查看设置区别
            </div>
          </lb-tool-tips>
          <div class="lb-text-red-tips">
            开启此功能前需联系售后配置，否则渠道码返佣将会失效
          </div>
        </el-form-item>
        <el-form-item
          label="关注公众号自动回复"
          prop="wechat_reply_text"
          v-if="subForm.wechat_qr_type === 1"
        >
          <el-input
            type="textarea"
            :rows="10"
            placeholder="请输入关注公众号自动回复内容"
            v-model="subForm.wechat_reply_text"
            resize="none"
          ></el-input>
        </el-form-item>
        <el-form-item label="公众号二维码" prop="web_code_img">
          <lb-cover
            :fileList="subForm.web_code_img"
            @selectedFiles="getCover($event, 'web_code_img')"
          ></lb-cover>
          <lb-tool-tips
            >图片建议尺寸：750 * n(高度不限)
            <div class="mt-sm">
              商家/平台需要自己上传自己设计好的公众号二维码海报图，用户进入h5之前可以先关注公众号
            </div>
            <div class="mt-sm">
              用户扫描分销合伙人的推广海报/渠道码，就会直接跳转到系统里面的引导用户关注公众号的页面
            </div>
          </lb-tool-tips>
          <div>
            <a
              class="c-link cursor-pointer"
              href="https://docs.qq.com/doc/DWXlGeVlWdlhOTnh6"
              target="_blank"
              >如何获取公众号二维码？</a
            >
          </div>
        </el-form-item>
        <el-form-item>
          <lb-button type="primary" @click="submitFormInfo" v-preventReClick>{{
            $t('action.submit')
          }}</lb-button>
        </el-form-item>
      </el-form>

      <el-dialog
        title="查看设置区别"
        :visible.sync="showDialog"
        width="800px"
        center
      >
        <div class="gzh-img-list">
          <div class="c-title text-bold mb-md">开启扫码到公众号</div>
          <div class="flex-y-center">
            <img src="https://lbqny.migugu.com/admin/anmo/pc/gzh01.png" />
            <i class="iconfont iconshengji"></i>
            <img src="https://lbqny.migugu.com/admin/anmo/pc/gzh03.png" />
          </div>
          <div class="c-title text-bold mt-lg pt-lg mb-md">
            关闭扫码到公众号
          </div>
          <div class="flex-y-center">
            <img src="https://lbqny.migugu.com/admin/anmo/pc/gzh01.png" />
            <i class="iconfont iconshengji"></i>
            <img src="https://lbqny.migugu.com/admin/anmo/pc/gzh02.png" />
            <i class="iconfont iconshengji"></i>
            <img src="https://lbqny.migugu.com/admin/anmo/pc/gzh03.png" />
          </div>
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      showDialog: false,
      subForm: {
        web_app_id: '',
        web_app_secret: '',
        map_secret: '',
        web_code_img: [],
        wechat_qr_type: 0,
        wechat_reply_text: ''
      },
      subFormRules: {
        web_app_id: { required: true, validator: this.$reg.isNotNull, text: '公众号AppID', reg_type: 2, trigger: 'blur' },
        web_app_secret: { required: true, validator: this.$reg.isNotNull, text: '公众号AppSecret', reg_type: 2, trigger: 'blur' },
        map_secret: { required: true, validator: this.$reg.isNotNull, text: '腾讯地图key', reg_type: 2, trigger: 'blur' },
        web_code_img: { required: true, type: 'array', message: '请上传公众号二维码', trigger: 'blur' },
        wechat_qr_type: { required: true, type: 'number', message: '请选择扫码方式', trigger: 'blur' }
      }
    }
  },
  created () {
    this.getFormInfo()
  },
  methods: {
    getCover (img, key) {
      this.subForm[key] = img
    },
    async getFormInfo () {
      let { code, data } = await this.$api.system.configInfo()
      if (code !== 200) return
      data.web_code_img = data.web_code_img ? [{ url: data.web_code_img }] : []
      for (let i in this.subForm) {
        this.subForm[i] = data[i]
      }
    },
    submitFormInfo () {
      this.$refs['subForm'].validate(valid => {
        if (valid) {
          let subForm = JSON.parse(JSON.stringify(this.subForm))
          subForm.web_code_img = subForm.web_code_img[0].url
          this.$api.system.configUpdate(subForm).then(res => {
            if (res.code === 200) {
              this.$message.success(this.$t('tips.successSub'))
            }
          })
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.lb-system-h5 {
  width: 100%;
  .el-input {
    width: 300px;
  }
  .el-textarea {
    width: 600px;
  }
  .gzh-img-list {
    img {
      height: 300px;
    }
    i {
      font-size: 10px;
      margin: 0 10px;
      color: #19c865;
      transform: scale(0.8);
    }
  }
}
</style>
